package com.openbravo.pos.util;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Random;

public class StringUtils
{
  private static final char[] hexchars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
  private static final NumberFormat cardformat = new DecimalFormat("000000");
  private static final Random cardrandom = new Random();

  public static String getCardNumber()
  {
    return cardformat.format(Math.abs(System.currentTimeMillis()) % 1000000L) + cardformat.format(Math.abs(cardrandom.nextLong()) % 1000000L);
  }

  public static String encodeXML(String paramString)
  {
    if (paramString == null)
      return null;
    StringBuffer localStringBuffer = new StringBuffer();
    for (int i = 0; i < paramString.length(); i++)
    {
      char c = paramString.charAt(i);
      if (c == '&')
        localStringBuffer.append("&amp;");
      else if (c == '<')
        localStringBuffer.append("&lt;");
      else if (c == '>')
        localStringBuffer.append("&gt;");
      else if (c == '"')
        localStringBuffer.append("&quot;");
      else if (c == '\'')
        localStringBuffer.append("&apos;");
      else
        localStringBuffer.append(c);
    }
    return localStringBuffer.toString();
  }

  public static String byte2hex(byte[] paramArrayOfByte)
  {
    StringBuffer localStringBuffer = new StringBuffer(paramArrayOfByte.length * 2);
    for (int i = 0; i < paramArrayOfByte.length; i++)
    {
      int j = (paramArrayOfByte[i] & 0xF0) >> 4;
      int k = paramArrayOfByte[i] & 0xF;
      localStringBuffer.append(hexchars[j]);
      localStringBuffer.append(hexchars[k]);
    }
    return localStringBuffer.toString();
  }

  public static byte[] hex2byte(String paramString)
  {
    int i = paramString.length();
    if ((i & 0x1) != 0)
      throw new IllegalArgumentException("odd number of characters.");
    byte[] arrayOfByte = new byte[i >> 1];
    int j = 0;
    int k = 0;
    while (k < i)
    {
      int m = Character.digit(paramString.charAt(k++), 16) << 4;
      m |= Character.digit(paramString.charAt(k++), 16);
      arrayOfByte[j] = (byte)(m & 0xFF);
      j++;
    }
    return arrayOfByte;
  }

  public static String readResource(String paramString)
    throws IOException
  {
    InputStream localInputStream = StringUtils.class.getResourceAsStream(paramString);
    if (localInputStream == null)
      throw new FileNotFoundException(paramString);
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    byte[] arrayOfByte1 = new byte[1024];
    int i;
    while ((i = localInputStream.read(arrayOfByte1)) > 0)
      localByteArrayOutputStream.write(arrayOfByte1, 0, i);
    byte[] arrayOfByte2 = localByteArrayOutputStream.toByteArray();
    return new String(arrayOfByte2, "UTF-8");
  }

  public static boolean isNumber(String paramString)
  {
    if ((paramString == null) || (paramString.equals("")))
      return false;
    for (int i = 0; i < paramString.length(); i++)
    {
      int j = paramString.charAt(i);
      if ((j != 48) && (j != 49) && (j != 50) && (j != 51) && (j != 52) && (j != 53) && (j != 54) && (j != 55) && (j != 56) && (j != 57))
        return false;
    }
    return true;
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.util.StringUtils
 * JD-Core Version:    0.6.0
 */